package com.etc;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * @Auther: zhezhe
 * @Date: 2018/10/269:24
 * @Description:
 */
public class AvgSourceReduce extends Reducer<Text, IntWritable,Text,IntWritable>{
    @Override
    protected void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
        int sum  = 0;
        int count = 0;
        for (IntWritable value : values) {
            count++;
            sum = sum + value.get();
        }
        int average = (int) sum/count;
        System.out.println(sum+"------"+count+"------"+average);
        context.write(key,new IntWritable(average));
    }
}
